//
// Created by win10 on 24-12-27.
//


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LENGTH 100
void sortStringsByLength(char **strings,int count) {
    for (int i = 0; i < count; i++) {
        for(int j=0;j<count-i-1;j++) {
            if(strlen(strings[j])>strlen(strings[j+1])) {
                char *temp = strings[j];
                strings[j] = strings[j + 1];
                strings[j + 1] = temp;
            }
        }
    }
}
void printfStrings(char **strings,int count) {
    for (int i = 0; i < count; i++) {
        printf("%s\n", strings[i]);
    }
}

int main() {
    while (1) {
        int n;
        if (scanf("%d", &n) != 1 || n <= 0) {
            break;
        }
        getchar();
        char **strings = (char **)malloc(n * sizeof(char *));
        if (strings == NULL) {
            fprintf(stderr, "内存分配失败\n");
            return 1;
        }

        int count = 0;

        for (int i = 0; i < n; i++) {
            char input[MAX_LENGTH];
            if (!fgets(input, sizeof(input), stdin)) {
                break;
            }
            input[strcspn(input, "\n")] = 0;

            if (strcmp(input, "stop") == 0) {
                break;
            }

            if (strlen(input) > 0 && strlen(input) < MAX_LENGTH) {
                strings[count] = (char *)malloc((strlen(input) + 1) * sizeof(char));
                if (strings[count] == NULL) {
                    fprintf(stderr, "内存分配失败\n");
                    return 1;
                }
                strcpy(strings[count], input);
                count++;
            }
        }

        if (count > 0) {
            sortStringsByLength(strings, count);
            printfStrings(strings, count);
        }

        // 释放内存
        for (int i = 0; i < count; i++) {
            free(strings[i]);
        }
        free(strings);
    }
    return 0;
}
